package AccountBinding

import (
	"ToolLibray/jwtx"
	"context"
	"property_api/utils/result"
	"property_api/utils/xform"
	"property_service/property_service"

	"property_api/internal/svc"
	"property_api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PagesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PagesLogic {
	return &PagesLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PagesLogic) Pages(req *types.AccountBindingPageReq) (resp *types.PageRes, err error) {
	// todo: add your logic here and delete this line

	tenantID := jwtx.GetUserTenantId64(l.ctx)
	userIdStr := xform.Int64ToString(jwtx.GetUserId(l.ctx))

	where := &property_service.AccountBinding{
		TenantID:           tenantID,
		ID:                 req.ID,
		Code:               req.Code,
		Name:               req.Name,
		ClassificationCode: req.ClassificationCode,
		ClassificationName: req.ClassificationName,
		SubjectCode1:       req.SubjectCode1,
		SubjectName1:       req.SubjectName1,
		SubjectCode2:       req.SubjectCode2,
		SubjectName2:       req.SubjectName2,
		SubjectCode3:       req.SubjectCode3,
		SubjectName3:       req.SubjectName3,
		Remark:             req.Remark,
		CreatedAtuser:      req.CreatedAtuser,
		UpdatedAtuser:      userIdStr,
	}

	data, err := l.svcCtx.AssetService.AccountBindingPage(l.ctx,
		&property_service.AccountBindingPageReq{
			Page:  req.Page,
			Limit: req.Limit,
			Where: where,
		})
	if err != nil {
		return nil, err
	}
	return result.SucPage(data, types.AccountBinding{}).PageEd()
}
